package org.javaboy.vhr.controller.salary;

import org.javaboy.vhr.model.Salary;
import org.javaboy.vhr.responseBean.ServerResponse;
import org.javaboy.vhr.service.SalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/salary/sob")
public class SalaryController {
    @Autowired
    SalaryService salaryService;
    @GetMapping("/")
    public ServerResponse getAllSalary(){
        List<Salary> salaries = salaryService.getAllSalary();
        return ServerResponse.success("",salaries);
    }

    @PostMapping("/")
    public ServerResponse addSalary(@RequestBody Salary salary){
        salary.setCreateDate(new Date());
        int result = salaryService.addSalary(salary);
        if(result==1){
            return ServerResponse.success("添加成功");
        }
        return ServerResponse.error(1000,"添加失败");
    }

    @DeleteMapping("/{id}")
    public ServerResponse deleteSalary(@PathVariable Integer id){

        int result = salaryService.deleteSalary(id);
        if(result==1){
            return ServerResponse.success("删除成功");
        }
        return ServerResponse.error(1000,"删除失败");
    }

    @PutMapping("/")
    public ServerResponse updateSalary(@RequestBody Salary salary){

        int result = salaryService.updateSalary(salary);
        if(result==1){
            return ServerResponse.success("修改成功");
        }
        return ServerResponse.error(1000,"修改失败");
    }
}
